package lumis.portal.group.databaseviewmembership;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import lumis.util.query.IQueryFilter;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * An entry of the database view membership formula.
 *
 * @version $Revision: 10458 $ $Date: 2009-06-02 15:49:09 -0300 (Tue, 02 Jun 2009) $
 * @since 4.2.1
 */
@Entity
@Table(name="lum_GroupDbVwFormulaEntry")
@Cache(usage = CacheConcurrencyStrategy.NONE) // edited directly by DOUI
@GenericGenerator(name="portal-guid", strategy="lumis.portal.dao.hibernate.GuidGenerator")
public class DatabaseViewFormulaEntry
{
	@Id @GeneratedValue(generator="portal-guid")
	private String id;
	
	private String leftParentheses;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="fieldId")
	private DatabaseViewField field;
	
	private String operator;
	private String value;
	private String rightParentheses;
	private String logicalOperator;
	private int position;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="groupConfigId")
	private DatabaseViewGroupConfig groupConfig;
	
	/**
	 * Returns the identifier of this entry.
	 * @return the identifier.
	 * @since 4.2.1
	 */
	public String getId()
	{
		return id;
	}
	
	/**
	 * Returns a string containing left parentheses set in this entry.
	 * @return the left parentheses string.
	 * @since 4.2.1
	 */
	public String getLeftParentheses()
	{
		return leftParentheses;
	}
	
	/**
	 * Sets the left parentheses for this entry.
	 * @param leftParentheses the left parentheses string.
	 * @since 4.2.1
	 */
	public void setLeftParentheses(String leftParentheses)
	{
		this.leftParentheses = leftParentheses;
	}
	
	/**
	 * Returns the field this entry operates on.
	 * @return the field.
	 * @since 4.2.1
	 */
	public DatabaseViewField getField()
	{
		return field;
	}
	
	/**
	 * Sets the field this entry operates on.
	 * @param field the field.
	 * @since 4.2.1
	 */
	public void setField(DatabaseViewField field)
	{
		this.field = field;
	}
	
	/**
	 * Returns the operator used in this entry.
	 * @return the operator.
	 * @since 4.2.1
	 */
	public String getOperator()
	{
		return operator;
	}
	
	/**
	 * Sets the operator used in this entry.
	 * @param operator the operator.
	 * @since 4.2.1
	 */
	public void setOperator(String operator)
	{
		this.operator = operator;
	}
	
	/**
	 * Returns the value that this entry operates on.
	 * @return the value, in string format.
	 * @since 4.2.1
	 */
	public String getValue()
	{
		return value;
	}
	
	/**
	 * Sets the value that this entry operates on.
	 * @param value the value, in string format.
	 * @since 4.2.1
	 */
	public void setValue(String value)
	{
		this.value = value;
	}
	
	/**
	 * Returns a string containing right parentheses set in this entry.
	 * @return the right parentheses string.
	 * @since 4.2.1
	 */
	public String getRightParentheses()
	{
		return rightParentheses;
	}
	
	/**
	 * Sets the right parentheses for this entry.
	 * @param rightParentheses the right parentheses string.
	 * @since 4.2.1
	 */
	public void setRightParentheses(String rightParentheses)
	{
		this.rightParentheses = rightParentheses;
	}
	
	/**
	 * Returns the logical operator used between this entry and the next.
	 * @return {@link IQueryFilter#FILTER_CONCATENATION_AND} or
	 * {@link IQueryFilter#FILTER_CONCATENATION_OR}.
	 * @since 4.2.1
	 */
	public String getLogicalOperator()
	{
		return logicalOperator;
	}
	
	/**
	 * Sets the logical operator used between this entry and the next.
	 * @param logicalOperator {@link IQueryFilter#FILTER_CONCATENATION_AND} or
	 * {@link IQueryFilter#FILTER_CONCATENATION_OR}.
	 * @since 4.2.1
	 */
	public void setLogicalOperator(String logicalOperator)
	{
		this.logicalOperator = logicalOperator;
	}
	
	/**
	 * Returns the position of this entry in the formula.
	 * @return the position.
	 * @since 4.2.1
	 */
	public int getPosition()
	{
		return position;
	}
	
	/**
	 * Sets the position of this entry in the formula.
	 * @param position the position.
	 * @since 4.2.1
	 */
	public void setPosition(int position)
	{
		this.position = position;
	}
	
	/**
	 * Returns the group configuration this formula entry belongs to.
	 * @return the group configuration.
	 * @since 4.2.1
	 */
	public DatabaseViewGroupConfig getGroupConfig()
	{
		return groupConfig;
	}
	
	/**
	 * Sets the group configuration this formula entry belongs to.
	 * @param groupConfig the group configuration.
	 * @since 4.2.1
	 */
	public void setGroupConfig(DatabaseViewGroupConfig groupConfig)
	{
		this.groupConfig = groupConfig;
	}
}